package com.ctd.springframework.core.io;

import java.io.IOException;

/**
 * AbstractResource
 *
 * @author chentudong
 * @time 2019/3/24 13:03
 */
public abstract class AbstractResource implements Resource {
    /**
     * exists
     *
     * @return boolean
     */
    @Override
    public boolean exists() {
        try {
            return getFile().exists();
        } catch (IOException e) {
            e.printStackTrace();
            try {
                getInputStream().close();
                return true;
            } catch (Throwable e1) {
                e1.printStackTrace();
                return false;
            }
        }
    }

    /**
     * isReadable
     *
     * @return boolean
     */
    @Override
    public boolean isReadable() {
        return exists();
    }

    /**
     * isOpen
     *
     * @return boolean
     */
    @Override
    public boolean isOpen() {
        return false;
    }

    /**
     * isFile
     *
     * @return boolean
     */
    @Override
    public boolean isFile() {
        return false;
    }
}
